import { Toast } from 'antd-mobile'
import React, { useState } from 'react'
import Header from '../../components/Header/Header'
import {reqregister} from '../../http/api'
export default function Register(props) {

  const [user,setUser]=useState({
    phone:'',
    nickname:'',
    password:''
  })
  const doRegister=()=>{
    reqregister(user).then(res=>{
      if(res.data.code===200){
        Toast.show({
          content:res.data.msg
        })
        //跳转
        props.history.push('/login')
      }
    })
  }

  return (
    <div>
      <Header back title='注册'></Header>
      <div>user:{JSON.stringify(user)}</div>
          <div>手机号：<input type="text" value={user.phone} onChange={(e)=>setUser({...user,phone:e.target.value})}/></div>
          <div>用户号：<input type="text" value={user.nickname} onChange={(e)=>setUser({...user,nickname:e.target.value})}/></div>
          <div>密码：<input type="text" value={user.password} onChange={(e)=>setUser({...user,password:e.target.value})}/></div>
          <button onClick={()=>doRegister()}>确认注册</button>
    </div>
  )
}
